// ================================================================================
// 告警日志控制器实现
// ================================================================================

// ================================================================================
// 告警日志控制器实现
// ================================================================================

package alertLog

import (
	"context"
	"devops-super/api/alerts/v1"
	"devops-super/internal/model/mymodel"
	"devops-super/internal/service"
	"github.com/gogf/gf/v2/os/gtime"
)

// GetPageLst 分页获取告警日志列表
func (*ControllerV1) GetPageLst(ctx context.Context, req *v1.AlertLogGetPageLstReq) (res *v1.AlertLogGetPageLstRes, err error) {
	res = &v1.AlertLogGetPageLstRes{}
	res.PageLstRes, err = service.AlertLog().GetPageLst(ctx, req)
	return
}

// Add 新增告警日志
func (*ControllerV1) Add(ctx context.Context, req *v1.AlertLogAddReq) (res *v1.AlertLogAddRes, err error) {
	alertLog := req.ToEntity()
	alertLog.CreatedAt = gtime.Now()
	alertLog.UpdatedAt = gtime.Now()
	err = service.AlertLog().Add(ctx, alertLog)
	return
}

// Upt 更新告警日志
func (*ControllerV1) Upt(ctx context.Context, req *v1.AlertLogUptReq) (res *v1.AlertLogUptRes, err error) {
	alertLog := req.ToEntity()
	alertLog.Id = req.Id
	alertLog.UpdatedAt = gtime.Now()
	err = service.AlertLog().Upt(ctx, alertLog)
	return
}

// UptStatus 更新告警日志状态
func (*ControllerV1) UptStatus(ctx context.Context, req *v1.AlertLogUptStatusReq) (res *v1.AlertLogUptStatusRes, err error) {
	err = service.AlertLog().UptStatus(ctx, req.Id, req.HandleStatus)
	return
}

// Del 删除告警日志
func (*ControllerV1) Del(ctx context.Context, req *v1.AlertLogDelReq) (res *v1.AlertLogDelRes, err error) {
	err = service.AlertLog().Del(ctx, req.Id)
	return
}

// GetOne 获取单条告警日志
func (*ControllerV1) GetOne(ctx context.Context, req *v1.AlertLogGetOneReq) (res *v1.AlertLogGetOneRes, err error) {
	entity, err := service.AlertLog().GetOne(ctx, req.Id)
	if err != nil {
		return
	}
	res = &v1.AlertLogGetOneRes{
		Info: &mymodel.AlertLogResponse{
			Id:           entity.Id,
			SceneId:      entity.SceneId,
			Level:        entity.Level,
			BindTo:       entity.BindTo,
			BindId:       entity.BindId,
			DeptId:       entity.DeptId,
			Detail:       entity.Detail,
			Sampletime:   entity.Sampletime,
			HandleStatus: entity.HandleStatus,
			HandleTime:   entity.HandleTime,
			HandRemark:   entity.HandRemark,
			CreatedAt:    entity.CreatedAt,
			UpdatedAt:    entity.UpdatedAt,
		},
	}
	return
}

// GetOptions 获取告警日志选项
func (*ControllerV1) GetOptions(ctx context.Context, req *v1.AlertLogGetOptionsReq) (res *v1.AlertLogGetOptionsRes, err error) {
	res, err = service.AlertLog().GetOptions(ctx, req)
	return
}

// HandleLog 处理告警日志
func (*ControllerV1) HandleLog(ctx context.Context, req *v1.AlertLogHandleReq) (res *v1.AlertLogHandleRes, err error) {
	err = service.AlertLog().HandleLog(ctx, req.Id, req.HandleStatus, req.HandRemark)
	return
}

// BatchDel 批量删除告警日志
func (*ControllerV1) BatchDel(ctx context.Context, req *v1.AlertLogBatchDelReq) (res *v1.AlertLogBatchDelRes, err error) {
	err = service.AlertLog().BatchDel(ctx, req.Ids)
	return
}

// BatchHandle 批量处理告警日志
func (*ControllerV1) BatchHandle(ctx context.Context, req *v1.AlertLogBatchHandleReq) (res *v1.AlertLogBatchHandleRes, err error) {
	err = service.AlertLog().BatchHandle(ctx, req.Ids, req.HandleStatus, req.HandRemark)
	return
}
